<!-- Page to display the tags associated with the questions -->

<%@ include file="header.jsp"%>
 <script type="text/javascript">
function setCurrentMenu(){
	
	document.getElementById("1").setAttribute('style', 'background:#999999');
	document.getElementById("4").setAttribute('style', 'background:#999999');
	document.getElementById("3").setAttribute('style', 'background:#999999');
	document.getElementById("2").setAttribute('style', 'background:#0093e7');
}
</script>
<span class="welcome-head"> Tags
	<hr	style="height: 0px; border-bottom: 1px thin gray; margin-top: -2px;" />
</span>
<br />

<!-- Showing all the tags associated with the questions. -->
<%TagQuestionCounter tag;%>
<% 
	if(session.getAttribute("listOfTags")!=null){
	ArrayList<TagQuestionCounter> listOfTags = (ArrayList<TagQuestionCounter>) session.getAttribute("listOfTags");
%>

<% 		int numPages = 0;
		int count = 0;
		int increment = 1;
		int numRows = 0;
		int columnSize=5;

		String startIndexString = request.getParameter("startIndex");
		
		if(startIndexString == null) {
			startIndexString = "0";
		}

		int startIndex = Integer.parseInt(startIndexString);

		try {
			if(listOfTags.size()<=columnSize){
				numRows=1;
			} else if (listOfTags.size()%columnSize ==0) {
				numRows = listOfTags.size()/columnSize ;	
			} else {
				numRows = (listOfTags.size() / columnSize) + 1 ;
			}
			

			int numRecordsPerPage = 5;
			
			numPages = numRows /numRecordsPerPage ;

			int remain = numRows % numRecordsPerPage ;
			if(remain != 0) {
				numPages = numPages +1 ;
			}

			if ((startIndex + numRecordsPerPage) <= numRows) {
				increment = startIndex + numRecordsPerPage ;
			} else {

				if(remain == 0) {
					increment = startIndex + numRecordsPerPage ;
				} else {
					increment = startIndex + remain;
				}
			}

			for(count = startIndex; count < increment; count++) {
%>

<!-- Showing all the tags associated with the questions. -->
	<div style="margin:10px;">
		<table id="tags-browser">
			<tbody>
				<tr>
					<%
						for (int j = count*columnSize ; (j < (count*columnSize)+columnSize) && (j<listOfTags.size()); j++) {
						tag = listOfTags.get(j);
					%>
					<td class="content-tag" width="200px;">
						<a href="TagSearch?id=<%=tag.getTag_id()%>&name=<%=tag.getTag_name()%>" class="post-tag" title="" rel="tag"><%=tag.getTag_name()%> </a> 
						<span class="item-multiplier"> x <span class="item-multiplier-x">&nbsp;&nbsp;&nbsp;&nbsp; </span> <%=tag.getQuestionCount()%> 
						<span class="item-multiplier-count"> </span>
						</span>
						<div class="excerpt" style="height: 5px;"></div> 
					</td>
					<% } %>
				</tr>					
			</tbody>
		</table>
		<hr style="height:0px;border:1px dotted #999999;"/>
		<br />
		</div>	
		<% } %>
		<br>
		<br>
		<div style="position: absolute;bottom: 5px;right: 50px;">	
		 <% if(listOfTags.size() != 0){%>	
		Displaying Records:
		<% if(startIndex + numRecordsPerPage < numRows) { %>
		<%= " " + (startIndex+1) %> - <%= (increment*columnSize)  %>				
 		<% } else { %>	
		<%= " " + (startIndex*columnSize+1) %> - <%= (listOfTags.size()-(startIndex*columnSize+1))+startIndex*columnSize+1%>
		<% } %>
		of <%= listOfTags.size() %>
		<% if(startIndex != 0) { %>
		&nbsp;
		<a href="showTags.jsp?startIndex=<%=startIndex-numRecordsPerPage%>">Previous</a>&nbsp;
		<% } %>
		<% increment += numRecordsPerPage ; %>
		<% if(startIndex + numRecordsPerPage < numRows) { %>
		<a href="showTags.jsp?startIndex=<%=startIndex+numRecordsPerPage %> ">Next </a>
		<% }} %>
		<% } catch (Exception exc) {
			out.println(exc.toString());
		} // end try-catch
		%>
		<% } %>  
</div>


<%@ include file="footer.jsp"%>